#include "comm.hpp"

int main()
{
    //1.获取key值
    // key_t key = getKey();
    // cout<<"server key:"<<toHex(key)<<endl;
    // //2.创建共享内存
    // int shm_id = creatShm(key,SIZE);
    // cout<<"server shm_id:"<<shm_id<<endl;
    // //3.关联共享内存
    // char* shm_address_start = attchShm(shm_id);

    //获取共享内存的状态信息
    // struct shmid_ds ds;
    // int n = shmctl(shm_id,IPC_STAT,&ds);
    // // if(n != -1)
    // {
    //     cout<<"perm："<<toHex(ds.shm_perm.__key)<<endl;  //查看key值
    //     cout<<"process->"<<getpid()<<":create shm_id:"<<ds.shm_cpid<<endl;  //查看哪个进程创建的
    // }
    Init s(SERVER);
    char* shm_address_start = s.Start();
    int n = 0;
    //开始通信
    while(n < 30)  //server读取数据
    {
       cout<<"client#"<<shm_address_start<<endl;
       n++;
       sleep(1);
    }

    //sleep(15);
    //4.取消关联
    // unlinkShm(shm_address_start);
    // // sleep(15);
    // //释放共享内存
    // delShm(shm_id);
    return 0;
}